package swle.xyz.austers.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import swle.xyz.austers.R;
import swle.xyz.austers.myclass.CurrentUser;

public class SettingsActivity extends AppCompatActivity {
    private Toolbar toolbar;
    private Button button_identity_authenticate;
    private Button button_about;
    private Button button_account_bound;
    private Button button_exit_account;
//    private Button button_exit_app;
    private Button button_user_information;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        initView();
        initEvent();
    }
    private void initView(){

        toolbar = findViewById(R.id.toolbar_settingsActivity);
        setSupportActionBar(toolbar); //将toolbar设置为当前activity的操作栏
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//添加默认的返回图标
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();

            }
        });
        getSupportActionBar().setHomeButtonEnabled(true);//设置返回键可用
        getSupportActionBar().setDisplayShowTitleEnabled(false);//隐藏toolbar默认显示的label

        button_identity_authenticate = findViewById(R.id.button_identity_authenticate);
        button_about = findViewById(R.id.button_about);
        button_account_bound = findViewById(R.id.button_account_bound);
        button_exit_account = findViewById(R.id.button_exit_account);
        button_user_information = findViewById(R.id.button_user_information);
//        button_exit_app = findViewById(R.id.button_exit_app);

    }

    private void initEvent(){

        button_identity_authenticate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CurrentUser currentUser = CurrentUser.getInstance();
                if (currentUser.isStudent){  //判断当前用户是否是经过身份认证
                    Toast.makeText(getApplicationContext(),"当前用户已认证",Toast.LENGTH_LONG).show();
                }else {
                    Intent intent = new Intent(SettingsActivity.this,IdentityAuthenticateActivity.class);
                    startActivity(intent);
                }

            }
        });



        button_account_bound.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingsActivity.this,AcountBoundActivity.class);
                startActivity(intent);
            }
        });

        button_user_information.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingsActivity.this,PersonalInfoActivity.class);
                startActivity(intent);
            }
        });

        button_about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingsActivity.this,AboutActivity.class);
                startActivity(intent);
            }
        });

        button_exit_account.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingsActivity.this, LogInActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK); //禁止回跳SignInActivity
                intent.setClass(SettingsActivity.this,LogInActivity.class);
                startActivity(intent);
            }
        });

//        button_exit_app.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                System.exit(0);
//            }
//        });

    }
}
